<template>
  <div class="page has-navbar" v-nav="{ title: title, showBackButton: true, onBackButtonClick: back }">
    <div class="page-content text-center">
      <div class="index">
        <div v-for="(item, key) in filterFoodsList" :key="item.id">
          <about-cell :newsObj="item"  ></about-cell>
        </div>
        <div v-for="(item, key) in filterSalesList"  :key="item.id">
          <about-cell :newsObj="item"  ></about-cell>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import aboutCell from './aboutCell.vue'
  export default {
    data() {
      return {
        title: '关于我们(mock数据)',
        foodsList: [],
        salesList: []
      }
    },
    components: {
      aboutCell
    },
    created() {
      this.initData()
    },
    // 数据渲染前预处理
    // 使用迭代器对请求的列表数据做处理（对“时间”列进行处理，只显示年月日，不显示时分秒）
    computed: {
      filterFoodsList() {
        let tmpDataList = this.foodsList
         tmpDataList.forEach(todo=>{
           let tmpDate = todo.date
           todo.date = tmpDate.substr(0,10)
         });
         return tmpDataList;
      },
      filterSalesList() {
        let tmpDataList = this.salesList
         tmpDataList.forEach(todo=>{
           let tmpDate = todo.date
           todo.date = tmpDate.substr(0,10)
         });
         return tmpDataList;
      },
    },
    methods: {
      async initData() {
        let result = await this.GLOBAL.api.aboutService.list()
        this.foodsList = result.data.foods;
        this.salesList = result.data.sales;
      },
      back() {
        $router.back('/')
      }
    }
  }
</script>
